package org.example.config.sequence;

import org.example.config.sequence.inspect.Inspector;
import org.example.config.sequence.listeners.MyApplicationListener;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * {@link SpringBootApplication @SpringBootApplication}相当于{@link SpringBootConfiguration @SpringBootConfiguration}、{@link EnableAutoConfiguration @EnableAutoConfiguration}和{@link ComponentScan @ComponentScan}
 * <p>
 * 其本身也是一个{@link Configuration @Configuration} 即 {@link Component @Component}
 * <p>
 * 如果{@link ComponentScan @ComponentScan}与{@link SpringBootApplication @SpringBootApplication}同时在启动类上使用，则{@code SpringBootApplication}失去{@code EnableAutoConfiguration}的能力
 */
// @ComponentScan()
@SpringBootApplication
public class SpringConfigApplication {
    public static void main(String[] args) {
        try {
            SpringApplication.run(SpringConfigApplication.class, args);
        } catch (Exception ex) {
            Inspector.log(SpringConfigApplication.class, "error " + ex.getMessage());
        }
        Inspector.log(SpringConfigApplication.class, "main");
    }

    @Bean
    public MyApplicationListener myApplicationListener() {
        Inspector.log(SpringConfigApplication.class, "creating MyApplicationListener");
        return new MyApplicationListener();
    }
}
